package com.systop.asset.controller;

import com.systop.asset.entity.RestResponse;
import com.systop.asset.entity.vo.MaterialTransferDetailVo;
import com.systop.asset.entity.vo.MaterialTransferVo;
import com.systop.asset.service.impl.MaterialTransferServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/materialTransfer")
public class MaterialTransferController {
    @Autowired
    private MaterialTransferServiceImpl materialTransferService;

    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody MaterialTransferVo materialTransferVo) {
        System.out.println(materialTransferVo);
        Long mtId = materialTransferService.addMaterialTransfer(materialTransferVo);
        if (mtId == null) {
            RestResponse.failure(500, "耗材添加失败");
        }
        return RestResponse.success();
    }

    /* 耗材列表*/
    @GetMapping("/list")
    public RestResponse<MaterialTransferVo> list(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                 @RequestParam(required = false) String orderNo) {
        MaterialTransferVo materialTransferList = materialTransferService.getMaterialTransferList(page, pageSize, orderNo);
        return RestResponse.success(materialTransferList);
    }

    /**
     * 根据ID 查询耗材详情
     */
    @GetMapping("detail/{id}")
    public RestResponse<MaterialTransferDetailVo> detail(@PathVariable int id) {
        MaterialTransferDetailVo materialTransferDeatilList = materialTransferService.getMaterialTransferDeatilList(id);

        return RestResponse.success(materialTransferDeatilList);
    }

    /*
     * 修改耗材状态
     * */
    @PutMapping("/upStatus/{mtId}/{status}")
    public RestResponse<?> upStatus(@PathVariable int mtId, @PathVariable int status) {
        materialTransferService.upMTStatus(mtId, status);
        return RestResponse.success();
    }


}
